2020国产情侣在线视频播放_99久久精品自慰喷水_男人的天堂AV网站_精品久久久久中文字幕加勒比

 
技術(shù)博客INFO
聯(lián)系我們CONTACT

公司地址:茂名市人民南路新村大院22號(hào)101

電話:13592986386

如何在ashx頁(yè)面獲取Session值您當(dāng)前的位置:首頁(yè) > 如何在ashx頁(yè)面獲取Session值

如何在ashx頁(yè)面獲取Session值

發(fā)布時(shí)間:2014/10/17 11:23:13

如何在ashx頁(yè)面獲取Session值

在一般事務(wù)處理頁(yè)面,可以輕松的得到 Request,Response對(duì)象,從而進(jìn)行相應(yīng)的操作,如下:

HttpRequest Request = context.Request; 

HttpResponse Response = context.Response;

但是要得到 Session的值就沒(méi)有那么簡(jiǎn)單了。比如你要在ashx得到保存在Session中的登錄帳號(hào)Session["userAccount"]

如果你只是context.Session["userAccount"]的話是會(huì)報(bào) “未將對(duì)象引用設(shè)置到對(duì)象的實(shí)例”的異常

所以,如果要想取Session中的值 ,需要如下所示

1、引入 命名空間:

using System.Web.SessionState;

2、實(shí)現(xiàn)IRequiresSessionState接口,具體如下  

    /// <summary>
    /// $codebehindclassname$ 的摘要說(shuō)明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class AddUserInfo : IHttpHandler,IRequiresSessionState //就是這樣顯示的實(shí)現(xiàn)一下,不用實(shí)現(xiàn)什么方法
    {

        public void ProcessRequest(HttpContext context)
        {

      //...

       //這樣你就可以如下 操作了

                if(context.Session["userAccount"] != null)

      {

        string account = context.Session["userAccount"].ToString();

      }

      //...繼續(xù)下面的代碼

    }

  }